package com.echo.im.engin.netty.processor.impl.in;

import com.echo.im.common.enums.IMCmdType;
import com.echo.im.domain.common.MessageDTO;
import com.echo.im.domain.group.dto.GroupMessagePacket;
import com.echo.im.domain.group.message.GroupMessageService;
import com.echo.im.engin.netty.processor.preprocessor.PreprocessorContext;
import com.echo.im.engin.netty.processor.MessageInProcessor;
import io.netty.channel.ChannelHandlerContext;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * @author: echo
 * @time: 2024-08-22
 */
@Component
@RequiredArgsConstructor
public class GroupMessageInProcessor implements MessageInProcessor<GroupMessagePacket> {

    private final GroupMessageService groupMessageService;

    private final PreprocessorContext preprocessorContext;

    @Override
    public void inProcess(ChannelHandlerContext ctx, GroupMessagePacket packet) {
        MessageDTO<GroupMessagePacket> messageDTO = new MessageDTO<>();

        messageDTO.setPacket(packet);

        preprocessorContext.doPreprocess(messageDTO);

        groupMessageService.sendMessage(messageDTO);

    }

    @Override
    public IMCmdType getCmdType() {
        return IMCmdType.GROUP_MESSAGE;
    }

    @Override
    public GroupMessagePacket transForm(Object o) {
        return null;
    }
}
